package com.example.user_service.user_contorller.FService.impl;

import com.example.user_service.user_contorller.FDao.UserMapper;
import com.example.user_service.user_contorller.FService.UserService;
import com.example.user_service.vo.UserDataVO;
import com.example.user_service.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fcr
 * @date 2021-12-14 11:35
 **/

@Service
public class UserServiceimpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public boolean f_login(int userid, String paswd) {
        UserVO userVO=userMapper.f_login(userid,paswd);
        if(userVO.getUser_id()!=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean f_checkid(int userid, String idcard) {
        UserVO userVO=userMapper.f_checkid(userid,idcard);
        if(userVO.getUser_id()!=0){
            return true;
        }
        return false;
    }

    @Override
    public String updateemail(int userid, String email) {
        System.out.println(userid + "===" + email);
        UserVO userVO=userMapper.f_checkemail(email);
        if(userVO!=null){
            System.out.println("beuse");
            return "beuse";
        }
        int result=userMapper.updateemail(userid,email);
        if(result!=0){
            System.out.println("success");
            return "success";
        }
        System.out.println("error");
        return "error";
    }

    @Override
    public boolean updatephone(int userid, String tel) {
        int result=userMapper.updatephone(userid,tel);
        if (result!=0){
            return true;
        }
        return false;
    }

    @Override
    public int selectmytype(int userid) {
        return userMapper.selectmytype(userid);
    }

    @Override
    public boolean updatetype(int userid) {
        return userMapper.updatetype(userid);
    }

    @Override
    public int forgetpwd(String paswd, String tel) {
        return userMapper.forgetpwd(paswd,tel);
    }

    @Override
    public UserVO selectmydata(int userid) {
        UserVO list=userMapper.selectmylogin(userid);
        if (list!=null){
            UserDataVO userDataVO=userMapper.selectmydata(list.getUser_id());
            list.setUserData(userDataVO);
        }

        return list;
    }

    @Override
    public boolean datachange(UserVO userVO, UserDataVO userDataVO) {
        userMapper.changeaccount(userVO.getAccount(),userVO.getUser_id());
        int result=userMapper.datachange(userDataVO.getUser_zsxm(),userDataVO.getUser_birthday(),userDataVO.getUser_gender(),userDataVO.getUser_area(),userVO.getUser_id());
        if (result==0){
            return false;
        }
        return true;
    }

    @Override
    public int changehead(String url,int user_id) {

        return userMapper.changehead(url,user_id);
    }

    @Override
    public int updatepwd(String paswd, int userid) {
        return userMapper.updatepwd(paswd,userid);
    }

}
